<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../sortie.php?sortie=3") ; }
 Include ($_SESSION ["repertoire_config"]."/garennes.cfg") ;
 Include ($_SESSION ["repertoire_config"]."/init.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 $requete = var_courante ("requete", 0, null) ;
 echo $requete;
 If (IsSet ($requete))
  {
   $id_type_appreciation = var_courante ("id_type_appreciation", 0, 0) ;
   $nom = var_courante ("nom", 0, "") ;
   $id_biblio_appreciation = var_courante ("id_biblio_appreciation", 0, 0) ;
   Switch ($requete)
    {
     // Insertion d'une d'appreciation
     Case 0 : $ok = SQL_commande ("INSERT INTO biblio_appreciations (type_appreciation, nom) VALUES ('".$id_type_appreciation."', '".Str_Replace ("'", "`", $nom)."')", $id_sql) ;
	      $requete = 0 ;
              Break ;
     // Effacement d'une d'appreciation
     Case 1 : $ok = SQL_commande ("DELETE FROM biblio_appreciations WHERE id_biblio_appreciation='".$id_biblio_appreciation."'", $id_sql) ;
	      $requete = 0 ;
	      Break ;
     // Debut de modification
     Case 2 : $resultat = SQL_commande ("SELECT b.id_biblio_appreciation, b.type_appreciation, b.nom FROM biblio_appreciations b, types_appreciations t WHERE b.id_biblio_appreciation='".$id_biblio_appreciation."' AND b.type_appreciation=t.id_type_appreciation", $id_sql) ;
              $modif = SQL_tableau_associatif ($resultat, "") ;
	      $requete = 3 ;
              Break ;
     // Fin de modification
     Case 3 : $debug_SQL=1;
              $ok = SQL_commande ("UPDATE biblio_appreciations SET type_appreciation='".$id_type_appreciation."',nom='".$nom."' WHERE id_biblio_appreciation='".$id_biblio_appreciation."'", $id_sql) ;
	      $debug_SQL=0;
	      $requete = 0 ;
              Break ;
    }
  }
 Else
  { $requete = 0 ; }

 If ($requete == 0)
  {
   $modif ["nom"] = "" ;
   $modif ["type_appreciation"] = $modif ["id_biblio_appreciation"] = 0 ;
  }
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 
 Echo "<HTML>" ;
 Echo " <HEAD>" ;
 entete_html ("Garennes", "travail", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Include ("./gestion_periodes.js") ;
 Echo " </HEAD>" ;
 
 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\" OnContextMenu=\"return false\">" ;
 Echo "<TABLE WIDTH=\"100%\" BORDER=0 CELLSPACING=0 CELLPADDING=0>" ;
 Echo "<TR>" ;
 Echo "<TD WIDTH=\"100%\" ALIGN=CENTER>Gestion&nbsp;de&nbsp;la&nbsp;biblioth&egrave;que&nbsp;d'appr&eacute;ciations</TD>" ;
 Echo "</TR>" ;
 Echo "</TABLE>" ;
 Echo "<TABLE ALIGN=CENTER BORDER=0 CELLSPACING=1 CELLPADDING=0>" ;
 Echo "<TR>" ;
 Echo "<TD vALIGN=TOP>" ;
 Echo "<TABLE ALIGN=CENTER BORDER=1 CELLSPACING=0 CELLPADDING=0 style=\"border:1px #000000 solid;border-collapse:collapse\">" ;
 Echo "<FORM METHOD=\"POST\" ACTION=\"./gestion_appreciations.php\">" ;
 Echo "<TR>" ;
 Echo "<TD COLSPAN=4>" ;
 Echo "<TABLE ALIGN=CENTER BORDER=0 BGCOLOR=\"".$l ["lien"]."\" WIDTH=\"100%\">" ;
 If ($requete == 0)
  {
   Echo "<TR><TD ALIGN=CENTER COLSPAN=5><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Ajouter</B>&nbsp;</FONT></TD></TR>" ;
  }
 Else
  {
   Echo "<TR><TD ALIGN=CENTER COLSPAN=5><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Modifier</B>&nbsp;</FONT></TD></TR>" ;
  }
 Echo "<TR BGCOLOR=\"".$l ["nom"]."\">" ;
 Echo "<TD ALIGN=CENTER><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Nom&nbsp;</TD>" ;
 Echo "<TD ALIGN=CENTER><FONT SIZE=\"".$l ["titre"]."\">&nbsp;Type&nbsp;</TD>" ;
 Echo "<TD BGCOLOR=\"".$l ["lien"]."\"></TD>" ;
 Echo "</TR>" ;
 Echo "<TR>" ;
 Echo "<TD ALIGN=CENTER><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<INPUT TYPE=\"TEXT\" NAME=\"nom\" VALUE=\"".$modif ["nom"]."\" SIZE=\"30\" MAXLENGTH=\"100\">&nbsp;</FONT></TD>" ;
 $type_appre = SQL_commande ("SELECT * FROM types_appreciations ORDER BY nom", $id_sql) ;
 Echo "<TD ALIGN=CENTER><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<SELECT NAME=\"id_type_appreciation\">" ;
 For ($i = 0 ; $i < SQL_nbr_lignes ($type_appre) ; $i++)
  {
   $tp = SQL_tableau_associatif ($type_appre, "") ;
   Echo "<OPTION VALUE=\"".$tp ["id_type_appreciation"]."\"" ;
   If ($modif ["type_appreciation"] == $tp ["id_type_appreciation"]) { Echo " SELECTED" ; }
   Echo ">".$tp ["nom"]."</OPTION>" ;
  }
 Echo "&nbsp;</FONT></TD>" ;
 Echo "<TD ALIGN=CENTER>" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_biblio_appreciation\" VALUE=\"".$modif ["id_biblio_appreciation"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"".$requete."\">" ;
 Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/ajouter.png\" ALT=\"Ajouter/Modifier appr&eacute;ciation\" VALUE=\"Ajouter\" BORDER=\"0\">" ;
 Echo "</TD></TR>" ;
 Echo "<TR><TD COLSPAN=5><FONT SIZE=\"".$l ["titre"]."\">&nbsp;</FONT></TD></TR>" ;
 Echo "</TABLE></TD></TR></TABLE></TD></TR>" ;
 Echo "</FORM>" ;
 
 // Bibliotheque deja saisies
 $resultat = SQL_commande ("SELECT b.id_biblio_appreciation, b.nom, t.nom AS nom_type FROM biblio_appreciations b, types_appreciations t WHERE b.type_appreciation=t.id_type_appreciation ORDER BY t.nom,b.nom", $id_sql) ;
 If (SQL_nbr_lignes ($resultat))
  {
   $nbr_p = 0 ;
   Echo "<TR><TD>&nbsp;</td></tr>" ;
   Echo "<TR><TD vALIGN=TOP>" ;
   Echo "<TABLE ALIGN=CENTER BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR=\"".$l ["couleur_fond"]."\" style=\"border:1px #000000 solid;border-collapse:collapse\">" ;
   Echo "<TR BGCOLOR=\"".$l ["lien"]."\">" ;
   Echo "<TD ALIGN=LEFT><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Nom</B>&nbsp;</FONT></TD>" ;
   Echo "<TD ALIGN=CENTER><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Type</B>&nbsp;</FONT></TD>" ;
   Echo "<TD ALIGN=CENTER><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Action</B>&nbsp;</FONT></TD>" ;
   Echo "</TR>" ;
   While ($ligne = SQL_tableau_associatif ($resultat, ""))
    {
     $nbr_p++ ;
     Echo "<TR" ;
     If ($nbr_p%2 == 0) { Echo " BGCOLOR=\"".$l ["nom"]."\"" ; }
     Echo ">" ;
     Echo "<TD ALIGN=LEFT><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["nom"]."&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=LEFT><FONT SIZE=\"".$l ["titre"]."\">&nbsp;".$ligne ["nom_type"]."&nbsp;</FONT></TD>" ;
     Echo "<TD ALIGN=CENTER>" ;
     Echo "<TABLE ALIGN=CENTER BORDER=0 CELLSPACING=0 CELLPADDING=0>" ;
     Echo "<TR>" ;
     Echo "<FORM ACTION=\"./gestion_appreciations.php\" METHOD=\"POST\">" ;
     Echo "<TD>" ;
     Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
     Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_biblio_appreciation\" VALUE=\"".$ligne ["id_biblio_appreciation"]."\">" ;
     Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"2\">" ;
     Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/edition.png\" ALT=\"&Eacute;diter l'appr&eacute;ciation\" BORDER=0>" ;
     Echo "</TD>" ;
     Echo "</FORM>" ;
     Echo "<FORM ACTION=\"./gestion_appreciations.php\" METHOD=\"POST\" onSubmit=\"return valide('".Str_Replace ("'", " ", $ligne ["nom"])." de type ".Str_Replace ("'", " ", $ligne ["nom_type"])."')\">" ;
     Echo "<TD>" ;
     Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
     Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_biblio_appreciation\" VALUE=\"".$ligne ["id_biblio_appreciation"]."\">" ;
     Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"1\">" ;
     Echo "<INPUT TYPE=\"IMAGE\" SRC=\"../images/effacer.png\" ALT=\"Supprimer l'appr&eacute;ciation\" BORDER=0>" ;
     Echo "</TD>" ;
     Echo "</FORM>" ;
     Echo "</TR></TABLE></TD></TR>";
    }
   Echo "</TD></TR></TABLE>" ;
  }
 Echo "</TABLE>" ;
 Echo "</FORM>" ;
 Echo "</BODY></HTML>" ;
?>